package com.spring03.demo.utils;

import jdk.jfr.Experimental;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TxManager {

    @Pointcut("execution(* com.spring03.demo.dao.impl.StudentDaoImpl.insert(..))")
    public void tx(){
    }

    @Before("tx()")
    public void begin() {
        System.out.println("开启事务");
    }

    @After("tx()")
    public void commit() {
        System.out.println("提交事务");
    }

    @AfterReturning("tx()")
    public void method01(){
        System.out.println("~~~~after returning");
    }

    @AfterThrowing("tx()")
    public void method02(){
        System.out.println("~~~~after throwing");
    }

    @Around("tx()")
    public Object logRecord(ProceedingJoinPoint point) throws Throwable {
        System.out.println("around-前置业务");
        Object v = point.proceed();
        System.out.println("around-后置业务");
        return v;
    }
}
